package com.thkj.modules.user.service.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.thkj.modules.user.entity.TblCameraRele;
import com.thkj.modules.user.entity.TblIndividual;
import com.thkj.modules.user.service.TblIndividualService;
import com.thkj.modules.user.service.TblMoniConfigService;

import dp.dao.PagingList;
import dp.service.BaseService;
import dp.util.DateUtil;

@Service
public class TblIndividualServiceImpl extends BaseService implements TblIndividualService {
	@Autowired
	private TblMoniConfigService tblMoniConfigService;

	public void insertTblIndividual(TblIndividual t) {
		dao.insert("com.thkj.mapper.TblIndividual.insert", t);
	}

	public Integer updateTblIndividual(TblIndividual t) {
		t.setUpdateTime(DateUtil.getNowAsTimestamp());
		int row = dao.update("com.thkj.mapper.TblIndividual.update", t);
		return row;
	}

	@Override
	public Integer updateCameraId(TblIndividual t) {
		int row = dao.update("com.thkj.mapper.TblIndividual.updateCameraId", t);
		return row;
	}

	@Override
	public Integer updateState(Map<String, String> param) {
		int row = dao.update("com.thkj.mapper.TblIndividual.updateState", param);
		return row;
	}

	public Integer deleteTblIndividual(String t) {
		return dao.update("com.thkj.mapper.TblIndividual.delete", t);
	}

	public TblIndividual getTblIndividualById(String t) {
		return dao.queryForObject("com.thkj.mapper.TblIndividual.getById", t, TblIndividual.class);
	}

	@Override
	public PagingList<Map> query(int pageIndex, int pageSize, Map<String, Object> param) {
		PagingList<Map> mapPagingList = dao.queryForPagingList("com.thkj.mapper.TblIndividual.query", param, pageIndex,
				pageSize, Map.class);

		List<Map> list = mapPagingList.getList();

		for (Map map : list) {
			String cameraId = (String) map.get("cameraId");
			TblCameraRele tblCameraRele = null;
			if (StringUtils.isNotBlank(cameraId)) {
				tblCameraRele = tblMoniConfigService.getById(cameraId);
			}
			map.put("bindCamera", tblCameraRele);
		}
		return mapPagingList;
	}

	@Override
	public Integer count() {
		return dao.queryForObject("com.thkj.mapper.TblIndividual.count", "", Integer.class);
	}

	@Override
	public List<Map> queryNoPage(Map<String, Object> param) {
		List<Map> maps = dao.queryForList("com.thkj.mapper.TblIndividual.query", param, Map.class);
		return maps;
	}

}